package com.itheima.exception;

import com.itheima.common.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ProjectExceptionHandler {

    //处理自定义异常
    @ExceptionHandler(CustomException.class)
    public R<String> doCustomException(CustomException ex){
        log.error(ex.getMessage());
        return R.error(ex.getMessage());
    }

    //处理其他异常
    @ExceptionHandler(Exception.class)
    public R<String> doException(Exception ex){
        log.error(ex.getMessage());
        return R.error(ex.getMessage());
    }
}
